//
//  SPEdudescFrame.m
//  iBaby365v2
//
//  Created by admin on 14/12/5.
//  Copyright (c) 2014年 suplus. All rights reserved.
//

#import "SPEdudescFrame.h"
#import "SPEducation.h"

@implementation SPEdudescFrame

/**
 *  计算文字尺寸
 *
 *  @param text    需要计算尺寸的文字
 *  @param font    文字的字体
 *  @param maxSize 文字的最大尺寸
 */
- (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize
{
    NSDictionary *attrs = @{NSFontAttributeName : font};
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}

-(void)setEducation:(SPEducation *)education
{
    _education = education;
    // 子控件之间的间距
    CGFloat padding = 10;
    
    // title的字体
    CGSize nameSize = [self sizeWithText:self.education.title font:[UIFont systemFontOfSize:17] maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
    CGFloat titleX = padding;
    CGFloat titleY = padding;
    _titleF = CGRectMake(titleX, titleY, nameSize.width, nameSize.height);
    
    // time的字体
    CGSize timeSize = [self sizeWithText:self.education.createTime font:[UIFont systemFontOfSize:14] maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
//    CGFloat timeX = [UIScreen mainScreen].bounds.size.width-padding-timeSize.width;
//    CGFloat timeY = CGRectGetMaxY(_titleF)-timeSize.height;
    CGFloat timeX = padding;
    CGFloat timeY = CGRectGetMaxY(_titleF)+padding;
    _timeF = CGRectMake(timeX, timeY, timeSize.width, timeSize.height);
    
    CGFloat picterueX = padding;
    CGFloat picterueY = CGRectGetMaxY(_timeF)+padding;
    CGFloat picterueW = [UIScreen mainScreen].bounds.size.width-2*padding;
    CGFloat picterueH = 180;
    _pictureF = CGRectMake(picterueX, picterueY, picterueW, picterueH);
    
    // 正文的字体
    CGSize contentTextSize = [self sizeWithText:self.education.content font:[UIFont systemFontOfSize:15] maxSize:CGSizeMake(picterueW, MAXFLOAT)];
    CGFloat contentTextX = padding;
    CGFloat contentTextY = padding+CGRectGetMaxY(_pictureF);
    _contentF = CGRectMake(contentTextX, contentTextY, contentTextSize.width, contentTextSize.height);
    _cellHight = CGRectGetMaxY(_contentF) + padding;
}
@end
